#include <iostream>
using namespace std;
int C=6;
void Knap(int *r,int *w,int *v,int n,int t,int &max,int weight,int value);
void main()
{
	int max=0;
	int weight=0,value=0;
	int w[]={5,3,2,1};
	int v[]={12,6,7,2};
	int n=4;
	int *r=new int[n];
	Knap(r,w,v,n,0,max,weight,value);
}

void Knap(int *r,int *w,int *v,int n,int t,int &max,int weight,int value)
{
	//cout<<t<<endl;
	int wei;
	int val;
	for(int i=1;i>=0;i--)
	{
		wei=weight;
		val=value;
		r[t]=i;
		wei+=r[t]*w[t];
		val+=r[t]*v[t];
		cout<<"wei"<<wei<<endl;
		cout<<"val"<<val<<endl;
		//int temp=constraint(r,w,v,t);
		if(wei<=C)
		{
			
			if(t==n-1)
			{
				if (max<val)
				{
					max=val;
					for (int k=0;k<=t;k++)
					{
						cout<<r[k];
					}
					cout<<"max"<<max<<endl;
				}
				
				return;
			}
			if(t<n-1)
			{
			//	cout<<"else"<<endl;
				Knap(r,w,v,n,t+1,max,wei,val);
			}
			
		}

	}
}

